package com.smartwebee.android.blespp.blockly;

import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import com.smartwebee.android.blespp.BleSppActivity;
import com.smartwebee.android.blespp.R;
import com.smartwebee.android.blespp.eventbusclass.SelectDevice;
import com.smartwebee.android.blespp.hospital.HospitalIndexActivity;
import com.smartwebee.android.blespp.hospital.HospitalScanActivity;
import com.smartwebee.android.blespp.utils.Utils;

import org.greenrobot.eventbus.EventBus;

import static com.smartwebee.android.blespp.utils.Utils.MODE_TYPE;

public class BlockScanActivity extends HospitalScanActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initSelfView();
    }

    private void initSelfView() {
        findViewById(R.id.btn_back).setVisibility(View.GONE);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                final BluetoothDevice device = adapter.getItem(position);
                if (device == null) return;
                if (mScanning) {
                    mBluetoothAdapter.stopLeScan(mLeScanCallback);
                    mScanning = false;
                    resetBtnText();
                }
//                final Intent intent = new Intent(BlockScanActivity.this, BlockIndexActivity.class);
//                intent.putExtra(BleSppActivity.EXTRAS_DEVICE_NAME, device.getName());
//                intent.putExtra(BleSppActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
//                startActivity(intent);
                EventBus.getDefault().post(new SelectDevice(device.getAddress(), device.getName()));
                finish();
            }
        });
    }
}
